package cn.com.byte1024.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.UUID;

/**
 * 通用工具类
 * @ProjectName: VoteSystem
 * @ClassName: CommonUtil
 * @Description:通用工具类
 * @Author: Kwnda
 * @Date: 2021/1/3 22:57
 */
public class CommonUtil {
	/**
	 * 生成 uuId
	 * 
	 * @return uuId
	 */
	public static String generateUUID() {
		
	    return UUID.randomUUID().toString().replaceAll("-", "");
	}

	private static char[] randRonstant = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};

	private static String GenerateRandomNumber(int Length) {
		StringBuilder newRandom = new StringBuilder(34);
		Random rd = new Random();
		for (int i = 0; i < Length; i++) {
			newRandom.append(randRonstant[rd.nextInt(34)]);
		}
		return newRandom.toString();
	}

	public static String generateCode() {
		//返回随机生成的6位验证码
		return GenerateRandomNumber(6);
	}

	/**
	 *
	 * @param nowDate   要比较的时间
	 * @param startDate   开始时间
	 * @param endDate   结束时间
	 * @return   true在时间段内，false不在时间段内
	 * @throws Exception
	 */
	public static boolean hourMinuteBetween(String nowDate, String startDate, String endDate) throws Exception{

		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

		Date now = format.parse(nowDate);
		Date start = format.parse(startDate);
		Date end = format.parse(endDate);

		long nowTime = now.getTime();
		long startTime = start.getTime();
		long endTime = end.getTime();

		return nowTime >= startTime && nowTime <= endTime;
	}

//	public static void main(String[] args) {
//	    System.out.println(generateUUID());
//		System.out.println(generateCode());
//		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//		try {
//			System.out.println(hourMinuteBetween("2021-01-04 22:14:48","2021-01-04 17:14:48","2021-01-05 12:14:48"));
//		}catch (Exception e){
//			
//		}
		
//	}
}
